package com.dmxh.service.impl;

import com.dmxh.mapper.TbOrderItemMapper;
import com.dmxh.pojo.TbOrderItem;
import com.dmxh.pojo.TbOrderItemExample;
import com.dmxh.service.OrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class OrderItemServiceImpl implements OrderItemService {

    @Autowired
    private TbOrderItemMapper orderItemMapper;

    @Override
    public int insertOrderItemList(List<TbOrderItem> orderItemList) {
        return orderItemMapper.insertOrderItemList(orderItemList);
    }

    @Override
    public Long queryOrderItemByOrderId() {
        List<TbOrderItem> orderItems = orderItemMapper.selectByExample(null);
        Long orderId = null;
        for (TbOrderItem orderItem : orderItems) {
            orderId = orderItem.getOrderId();
        }
        return orderId;
    }

    @Override
    public void deleteOrderItem(Long orderId) {
        TbOrderItemExample orderItemExample = new TbOrderItemExample();
        orderItemExample.createCriteria().andOrderIdEqualTo(orderId);
        orderItemMapper.deleteByExample(orderItemExample);
    }
}
